﻿using PmSoft.Events;
using PmSoft;
using Modules.Project.EventArgs;

namespace ManagementApi.EventModules;

/// <summary>
/// 项目事件订阅
/// </summary>
[UseDI(ServiceLifetime.Singleton, typeof(IEventMoudle))]
public class ProjectEventModule : IEventMoudle
{
    private readonly IEventBus eventBus;

    public ProjectEventModule(IEventBus eventBus)
    {
        this.eventBus = eventBus;
    }

    public void RegisterEventHandler()
    {
        eventBus.Subscribe<ProjectStatusChangeEventArgs, ProjectStatusChangeEventHandler>();
        eventBus.Subscribe<ProjectUnlockEventArgs, ProjectUnlockEventHandler>();
        eventBus.Subscribe<ProjectLockEventArgs, ProjectLockEventHandler>();
    }
}

/// <summary>
/// 项目锁定事件处理
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class ProjectLockEventHandler : IEventHandler<ProjectLockEventArgs>
{
    //private readonly CmsSupportService cmsSupportService;

    public ProjectLockEventHandler()
    {
     //   this.cmsSupportService = cmsSupportService;
    }

    public Task HandleAsync(object sender, ProjectLockEventArgs eventArgs)
    {
        //cmsSupportService.ProjectLock(new ProjectLockReq() { OrgID = eventArgs.LockCode, CorpCode = eventArgs.CorpCode, PrjName = eventArgs.PrjName });
        return Task.CompletedTask;
    }
}

/// <summary>
/// 项目解锁事件处理
/// </summary>

[UseDI(ServiceLifetime.Scoped)]
public class ProjectUnlockEventHandler : IEventHandler<ProjectUnlockEventArgs>
{
  //  private readonly CmsSupportService cmsSupportService;
    public ProjectUnlockEventHandler()
    {
     //   this.cmsSupportService = cmsSupportService;
    }

    public Task HandleAsync(object sender, ProjectUnlockEventArgs eventArgs)
    {
        //cmsSupportService.ProjectUnlock(eventArgs.LockCode);
        return Task.CompletedTask;
    }
}

/// <summary>
/// 项目状态变更事件处理
/// </summary>

[UseDI(ServiceLifetime.Scoped)]
public class ProjectStatusChangeEventHandler : IEventHandler<ProjectStatusChangeEventArgs>
{
    //private readonly CmsSupportService cmsSupportService;
    public ProjectStatusChangeEventHandler()
    {
     //   this.cmsSupportService = cmsSupportService;
    }

    public Task HandleAsync(object sender, ProjectStatusChangeEventArgs eventArgs)
    {
        //这里需要将状态推送到一体化平台
       // cmsSupportService.ProjectStatus(eventArgs.ProjectId);
       return Task.CompletedTask;
    }
}